var ns, app;
app = new Vue({
    el: '#app',
    data: {
        ID: 0,
        form: {
            UseStatus: 0,//0-审核中 1-审核拒绝 2-未通行 3-已放行 4-已失效
            UseStatusName: '',
            OwnerName: '',
            PhoneNumber: '',
            ItemInformation: '',//物品信息
            VehicleInformation: '',//车辆信息
            VisitTypeName: '',//通行事由
            ReleaseInstructions: '',//放行说明
            StartTime: '',
            QrCodeImgPath: '',
        },
        imglist: [],
        TrailList: [],
    },
    methods: {
        get_data: function () {
            var that = this;
            var options = {};
            options.ID = 0;
            options.IDs = that.ID;//会转码
            options.action = "getunderreview";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.form = data.data;
                    that.imglist = data.imglist;
                    that.TrailList = data.Model;
                    if (that.form.UseStatus == 3) {
                        webSocket.guid = 'fxapp' + that.form.ID;
                        webSocket.closeSocket();
                        setTimeout(function () {
                            webSocket.connectSocket();
                        }, 300)
                    };

                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        //放行
        doRelease: function () {
            var that = this;
            api.confirm({
                title: '提示',
                msg: '确认是否放行?',
                buttons: ['确定放行', '取消']
            }, function (ret, err) {
                if (ret.buttonIndex == 1) {
                    ns.post({
                        action: 'savaconfirmpassage',
                        ID: that.form.ID,
                    }, function (succeed, data, err) {
                        if (succeed) {
                            that.do_send();
                            api.toast({
                                msg: '操作成功',
                                duration: 2000,
                                location: 'bottom'
                            });

                        } else if (err) {
                            api.toast({
                                msg: err,
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                        setTimeout(function () {
                            api.closeWin();
                        }, 500);
                    });
                }
            });
        },
        //给微信端发送消息通过的通知
        do_send: function () {
            var that = this;
            var message = "扫码已通过刷新列表";
            //发送消息
            webSocket.sendSocketMessage({
                msg: {
                    messageType: 2,
                    guid: 'fxwx' + that.form.ID,
                    content: message
                },
                success: function (res) {
                    webSocket.closeSocket();
                }
            })
        },
        //拨打电话 
        tel_phone: function (phone) {
            api.call({
                type: 'tel_prompt',
                number: phone
            });
        },
        do_viewimages: function (activeIndex) {
            var that = this;
            var imageUrls = [];
            for (var i = 0; i < that.imglist.length; i++) {
                imageUrls.push(that.imglist[i].imgurl);
            }
            var imageBrowser = api.require('imageBrowser');
            imageBrowser.openImages({
                showList: false,
                activeIndex: activeIndex,
                imageUrls: imageUrls
            });
        },
    }
});
apiready = function () {
    api.parseTapmode();
    app.ID = api.pageParam.id; //二维码传值
    ns = window.Foresight.Util;
    app.get_data();
    setTimeout(function () {
        api.closeFrame({
            name: 'scanner_frm'
        });
    }, 500);

};
